import { createRouter, createWebHistory } from "vue-router";   

// 定义路由记录  
const routes = [  
    {  
        path: '/Login',  
        name: 'Login',  
        meta: { title: '登录页面' },  
        component: () => import('../components/Login.vue')  
    },
    {
        path: "/",
        redirect: 'Login'
    },  
    {  
        path: '/Main',  
        name: 'Main',  
        component: () => import('../components/Main.vue'),  
        meta: { title: '首页' },
        children:[
            {
                path: '/Home',
                component: () => import('../components/Home.vue')
            },
                    {
                        name: 'UserManagement',
                        path: '/UserManagement',
                        component: () => import('../components/SSM/UserManagement.vue'),
                        meta:{title:'用户列表'}
                    },
                    {
                        name: 'RoleManagement',
                        path: '/RoleManagement',
                        component: () => import('../components/SSM/RoleManagement.vue'),
                        meta:{title:'角色列表'}
                    },
                    {
                        name: 'MenuManagement',
                        path: '/MenuManagement',
                        component: () => import('../components/SSM/MenuManagement.vue'),
                        meta:{title:'菜单管理'}
                    },  {
                        name: 'SectionManagement',
                        path: '/SectionManagement',
                        component: () => import('../components/SSM/sectionManagement.vue'),
                        meta:{title:'部门管理'}
                    },{
                        name: 'PostManagement',
                        path: '/PostManagement',
                        component: () => import('../components/SSM/PostManagement.vue'),
                        meta:{title:'岗位管理'}
                    },
            {
                name: 'Product',
                path: '/Product',
                component: () => import('../components/BIP/Product.vue'),
                meta:{title:'产品信息'}
            },
            {
                name: 'Bom',
                path: '/Bom',
                component: () => import('../components/BIP/BOM.vue'),
                meta:{title:'物料制造BOM'}
            },
            {
                name: 'ProductForm',
                path: '/ProductForm',
                component: () => import('../components/BIP/ProductForm.vue'),
                meta:{title:'新增产品'}
            }, 
            {
                name: 'UpdateProductFrom',
                path: '/UpdateProductFrom',
                component: () => import('../components/BIP/UpdateProductFrom.vue'),
                meta:{title:'修改产品'}
            }, 
            {
                name: 'CheckProductForm',
                path: '/CheckProductForm',
                component: () => import('../components/BIP/CheckProductForm.vue'),
                meta:{title:'查看产品'}
            }, 
            {
                name: 'BomXq',
                path: '/BomXq',
                component: () => import('../components/BIP/BomXq.vue'),
                meta:{title:'Bom详情'}
            }, 
            {
                name: 'Process',
                path: '/Process',
                component: () => import('../components/BIP/Process.vue'),
                meta:{title:'生产工序'}
            },  {
                name: 'Processroute',
                path: '/Processroute',
                component: () => import('../components/BIP/Processroute.vue'),
                meta:{title:'工艺路线定义'}
            },
            {
                name: 'ConfigureProcessRoute',
                path: '/ConfigureProcessRoute',
                component: () => import('../components/BIP/ConfigureProcessRoute.vue'),
                meta:{title:'配置工艺路线'}
            },
            {
                name: 'Workorder',
                path: '/Workorder',
                component: () => import('../components/PPMS/Workorder.vue'),
                meta:{title:'生产工单'}
            }, 
            {
                name: 'ProductionOrder',
                path: '/ProductionOrder',
                component: () => import('../components/PPMS/ProductionOrder.vue'),
                meta:{title:'生产订单'}
            }, 
            {
                name: 'ProductionPlan',
                path: '/ProductionPlan',
                component: () => import('../components/PPMS/ProductionPlan.vue'),
                meta:{title:'生产计划'}
            }, 
            {
                name: 'Group',
                path: '/Group',
                component: () => import('../components/EM/Group.vue'),
                meta:{title:'生产班组配置'}
            }, 
            {
                name: 'Shift',
                path: '/Shift',
                component: () => import('../components/EM/Shift.vue'),
                meta:{title:'生产班次配置'}
            }, 
            {
                name: 'Calendar',
                path: '/Calendar',
                component: () => import('../components/EM/Calendar.vue'),
                meta:{title:'生产日历配置'}
            }, 
            {
                name: 'Attendance',
                path: '/Attendance',
                component: () => import('../components/EM/Attendance.vue'),
                meta:{title:'生产人员考勤'}
            }, 
            {
                name: 'Calculation',
                path: '/Calculation',
                component: () => import('../components/EM/Calculation.vue'),
                meta:{title:'生产工资计算'}
            }, 
            {
                name: 'Configuration',
                path: '/Configuration',
                component: () => import('../components/EM/Configuration.vue'),
                meta:{title:'工资计算配置'}
            },
            {
                name: 'DictManagement',
                path: '/DictManagement',
                component: () => import('../components/BI/DictManagement.vue'),
                meta:{title:'数据字典'}
            },
            {
                name: 'KSManagement',
                path: '/KSManagement',
                component: () => import('../components/BI/KSManagement.vue'),
                meta:{title:'客商信息'}
            },
            {
                name: 'PPManagement',
                path: '/PPManagement',
                component: () => import('../components/BI/PPManagement.vue'),
                meta:{title:'品牌管理'}
            }, 
            {
                name: 'DWManagement',
                path: '/DWManagement',
                component: () => import('../components/BI/DWManagement.vue'),
                meta:{title:'计量单位'}
            }, 
            {
                name: 'WLManagement',
                path: '/WLManagement',
                component: () => import('../components/BI/WLManagement.vue'),
                meta:{title:'物料信息'}
            },{
                name: 'AllocateWarehouse',
                path: '/AllocateWarehouse',
                component: () => import('../components/SM/AllocateWarehouse.vue'),
                meta:{title:'调拨出库'}
            },{
                name: 'TransferStorage',
                path: '/TransferStorage',
                component: () => import('../components/SM/TransferStorage.vue'),
                meta:{title:'调拨出库'}
            }, 
            {
                name: 'MaterialTransfer',
                path: '/MaterialTransfer',
                component: () => import('../components/SM/MaterialTransfer.vue'),
                meta:{title:'物料调拨'}
            },
            {
                name: 'RepositoryConfiguration',
                path: '/RepositoryConfiguration',
                component: () => import('../components/BIW/RepositoryConfiguration.vue'),
                meta:{title:'仓库配置'}
            },
            {
                name: 'ReservoirArea',
                path: '/ReservoirArea',
                component: () => import('../components/BIW/ReservoirArea.vue'),
                meta:{title:'库区'}
            },
            {
                name: 'BinLocation',
                path: '/BinLocation',
                component: () => import('../components/BIW/BinLocation.vue'),
                meta:{title:'库位'}
            },
            {
                name: 'KsMTK',
                path: '/KsMTK',
                component: () => import('../components/MTK/KsMTK.vue'),
                meta:{title:'客商模态框'}
            }
            ,
            {
                name: 'CPMTK',
                path: '/CPMTK',
                component: () => import('../components/MTK/CPMTK.vue'),
                meta:{title:'产品模态框'}
            }
            ,
            {
                name: 'PPMTK',
                path: '/PPMTK',
                component: () => import('../components/MTK/PPMTK.vue'),
                meta:{title:'品牌模态框'}
            },{
                name: 'WorkOrderProductionJobs',
                path: '/WorkOrderProductionJobs',
                component: () => import('../components/PPM/WorkOrderProductionJobs.vue'),
                meta:{title:'工单记录'}
            },
            {
                name: 'Workreportingrecord',
                path: '/Workreportingrecord',
                component: () => import('../components/PPM/Workreportingrecord.vue'),
                meta:{title:'报工记录'}
            },
            {
                name: 'ReportingandQuality',
                path: '/ReportingandQuality',
                component: () => import('../components/PPM/ReportingandQuality.vue'),
                meta:{title:'报工质检'}
            }, 
            {
                name: 'GCManagement',
                path: '/GCManagement',
                component: () => import('../components/BI/GCManagement.vue'),
                meta:{title:'工厂信息'}
            }, 
            {
                name: 'ZJXMManagement',
                path: '/ZJXMManagement',
                component: () => import('../components/BIQI/ZJXMManagement.vue'),
                meta:{title:'质检检查项目'}
            }, 
            {
                name: 'ZJBZManagement',
                path: '/ZJBZManagement',
                component: () => import('../components/BIQI/ZJBZManagement.vue'),
                meta:{title:'质量检验标准'}
            }, 
            {
                name: 'ZJQXManagement',
                path: '/ZJQXManagement',
                component: () => import('../components/BIQI/ZJQXManagement.vue'),
                meta:{title:'质检缺陷定义'}
            }
            , 
            {
                name: 'RawMaterialProcurement',
                path: '/RawMaterialProcurement',
                component: () => import('../components/RMM/RawMaterialProcurement.vue'),
                meta:{title:'采购订单'}
            }
            ,
            {
                name: 'AddRawMaterialProcurement',
                path: '/AddRawMaterialProcurement',
                component: () => import('../components/RMM/AddRawMaterialProcurement.vue'),
                meta:{title:'采购订单'}
            }
            ,
            {
                name: 'UpdateRawMaterialProcurement',
                path: '/UpdateRawMaterialProcurement',
                component: () => import('../components/RMM/UpdateRawMaterialProcurement.vue'),
                meta:{title:'采购订单'}
            }
            ,
            {
                name: 'UpRawMaterialProcurement',
                path: '/UpRawMaterialProcurement',
                component: () => import('../components/RMM/UpRawMaterialProcurement.vue'),
                meta:{title:'采购订单'},
                props: true, // 启用 props
            }
            ,
            {
                name: 'RawMaterialsArrived',
                path: '/RawMaterialsArrived',
                component: () => import('../components/RMM/RawMaterialsArrived.vue'),
                meta:{title:'原材料到货'}
            }
            ,
            {
                name: 'RawMaterialsStorage',
                path: '/RawMaterialsStorage',
                component: () => import('../components/RMM/RawMaterialsStorage.vue'),
                meta:{title:'原材料到货'}
            }
            ,
            {
                name: 'AddRawMaterialsStorage',
                path: '/AddRawMaterialsStorage',
                component: () => import('../components/RMM/AddRawMaterialsStorage.vue'),
                meta:{title:'入库作业'}
            }
            ,
            {
                name: 'GetRawMaterialsStorage',
                path: '/GetRawMaterialsStorage',
                component: () => import('../components/RMM/GetRawMaterialsStorage.vue'),
                meta:{title:'入库详情'}
            }
            ,
            {
                name: 'PickingWarehouse',
                path: '/PickingWarehouse',
                component: () => import('../components/RMM/PickingWarehouse.vue'),
                meta:{title:'领料出库'}
            }
            ,
            {
                name: 'PickingWarehouseXX',
                path: '/PickingWarehouseXX',
                component: () => import('../components/RMM/PickingWarehouseXX.vue'),
                meta:{title:'领料出库详细'}
            }
            ,
            {
                name: 'CKPickingWarehouse',
                path: '/CKPickingWarehouse',
                component: () => import('../components/RMM/CKPickingWarehouse.vue'),
                meta:{title:'领料出库作业'}
            }
            ,
            {
                name: 'WarehouseCountingOrder',
                path: '/WarehouseCountingOrder',
                component: () => import('../components/IM/WarehouseCountingOrder.vue'),
                meta:{title:'仓库盘点'}
            }
            ,
            {
                name: 'InventoryAdjustmentOrders',
                path: '/InventoryAdjustmentOrders',
                component: () => import('../components/IM/InventoryAdjustmentOrders.vue'),
                meta:{title:'盘点调整'}
            }
            ,
            {
                name: 'Finishedproduct',
                path: '/Finishedproduct',
                component: () => import('../components/RMM/Finishedproduct.vue'),
                meta:{title:'成品入库'}
            }
            ,
            {
                name: 'RKFinishedproduct',
                path: '/RKFinishedproduct',
                component: () => import('../components/RMM/RKFinishedproduct.vue'),
                meta:{title:'成品入库作业'}
            }
            ,
            {
                name: 'FinishedproductXX',
                path: '/FinishedproductXX',
                component: () => import('../components/RMM/FinishedproductXX.vue'),
                meta:{title:'成品入库详细'}
            }
        ]
    },    

];  

const router = createRouter({  
    history: createWebHistory(),  
    routes: routes  
});  

// 路由守卫  
router.beforeEach((to, from, next) => {  
    if (to.path !== '/Login') {  
        if (sessionStorage.getItem('u')) {  
            next();  
        } else {  
             ElMessage.error('你没有登录');  
            next({ path: '/Login' });  
        }  
    } else {  
        next();  
    }  
});  

router.afterEach((to) => {  
    document.title = to.meta.title || "hr"; // 设置页面标题  
});  

export default router;